<?php
if (isset($param[1])) {
	$produk = db_result("SELECT * FROM produk WHERE slug = '".amankan($param[1])."'");
	if ($produk == false) {
		echo "404 Page Not Found";
	} else {
		if (isset($_SESSION['status-tambah'])) {
			echo "<p>".$_SESSION['status-tambah']."</p>";
			unset($_SESSION['status-tambah']);
		}
		echo "<br>";
		echo "<img src=\"".site()."/asset/images/produk/".$produk['id'].".jpg\" width=\"250\" />";
		echo "<br>";
		echo $produk['nama']."<br>";
		echo int_to_rp($produk['harga'])."<br>";
		echo $produk['deskripsi']."<br>";
		echo $produk['kategori']."<br>";
		?>
		<form action="<?php echo site()."/produk-action/".$param[1] ?>" method="post">
			<input type="hidden" name="id" value="<?php echo $produk['id'] ?>" />
			<input type="text" name="kuantitas" value="0" onfocus="focusing(this)" onblur="bluring(this)" />
			<input type="submit" name="tambah" value="Tambah ke keranjang" />
		</form>
		<script type="text/javascript">
			function focusing(el) {
				if (el.value == "0") el.value = "";
			}
			function bluring(el) {
				if (el.value == "") el.value = "0";
			}
		</script>
		<?php
	}
} else {
	$kategoris = db_array("SELECT * FROM kategori ORDER BY isi ASC");
	if ($kategoris != false) {
		echo "Kategori : ";
		foreach ($kategoris as $kategori) {
			echo "<a href=\"".site()."/kategori/".$kategori['isi']."\">".$kategori['isi']."</a> ";
		}
		echo "<br>";
	}
	$produks = db_array("SELECT * FROM produk ORDER BY id DESC");
	foreach ($produks as $produk) {
		echo "<br>";
		echo "<img src=\"".site()."/asset/images/produk/".$produk['id'].".jpg\" width=\"150\" />";
		echo "<br>";
		echo "<a href=\"".site()."/".$param[0]."/".$produk['slug']."\">".$produk['nama']."</a><br>";
		echo int_to_rp($produk['harga'])."<br>";
	}
}
?>